﻿using System.Collections;
using System.Collections.Generic;

namespace winS.Unity
{
    internal static class CoroutineCorePool
    {
        private static readonly Stack<CoroutineCore> coroutineStack = new Stack<CoroutineCore>();

        public static CoroutineCore Pop(IEnumerator enumerator)
        {
            if (coroutineStack.Count == 0) return new CoroutineCore(enumerator);
            CoroutineCore coroutineCore = coroutineStack.Pop();
            coroutineCore.Initialize(enumerator);
            return coroutineCore;
        }
        public static void Push(CoroutineCore coroutine)
        {
            coroutine.Release();
            coroutineStack.Push(coroutine);
        }
    }
}